<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
<!--教师：查询学生考试成绩交互界面-->
    <div class="easyui-tabs" style="width:100%;height:100%">
        <div title="查询教师任课成绩" style="padding:3px">
            <table id="dg_queryMyTeachScore" style="height:100%">
            </table>
            <div id="queryMyTeachScore_toolbar">
                <form id="exportMyTeachScoreId" method="post" action="exportMyTeachScoreData" >
                    <input id="teachGradeNameId" name="gradeName" type="text" hidden>
                <div class="param-div">
                    <select id="myTeachGradeDatatableName" name="gradeDatatableName" class="form-control-sm">
                        <option value="">请选择年级...</option>
                        <option th:each="gra:${session.grades}" th:value="${gra.gradeDatatableName}" th:text="${gra.gradeName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="myTeachTeamName" name="teamName" class="form-control-sm" >
                        <option value="">请选择班级...</option>
                        <option th:each="team:${session.teams}" th:value="${team}" th:text="${team}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="myTeachSemesterName" name="semesterName" class="form-control-sm" >
                        <option value="">请选择学期...</option>
                        <option th:each="semes:${session.semesters}" th:value="${semes.semesterName}" th:text="${semes.semesterName}"></option>
                    </select>
                </div>
                <div class="param-div" style="width: 200px;">
                    <select id="myTeachExamName" name="examName" class="form-control-sm" style="width: 200px;">
                        <option value="">请选择考试...</option>
                        <option th:each="exa:${session.exams}" th:value="${exa.examName}" th:text="${exa.examName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="myTeachCourseName" name="courseEnName" class="form-control-sm">
                        <option value="">请选择学科...</option>
                        <option th:each="cour:${session.courses}" th:value="${cour.courseEnName}" th:text="${cour.courseChName}"></option>
                    </select>
                </div>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doQueryMyTeachScore()">查询</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-export" plain="true" onclick="doExportTeachScore()">导出</a>
                </form>
            </div>
        </div>
    </div>
<script type="text/javascript" th:inline="none">
    $(function () {
        //分页参数
        let pageParam = {
            pageSize: 10,							//每页显示的记录条数，默认为70
            pageList: [10, 100, 300, 500, 1000],	//可以设置每页记录条数的列表
            beforePageText: '第',        			//页数文本框前显示的汉字
            afterPageText: '页    共 {pages} 页',
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        }
        //查询教师成绩
        $("#dg_queryMyTeachScore").datagrid({
            url: "queryMyTeachScore",
            queryParams:{
                gradeName: $("#myTeachGradeDatatableName").find("option:selected").text(),
                gradeDatatableName: $("#myTeachGradeDatatableName").val(),
                teamName: $("#myTeachTeamName").val(),
                semesterName: $("#myTeachSemesterName").val(),
                examName: $("#myTeachExamName").val(),
                courseEnName: $("#myTeachCourseName").val()
            },
            toolbar: "#queryMyTeachScore_toolbar",
            pagination: true,
            pageSize: 10,
            rownumbers: true,
            fitColumns: false,
            singleSelect: false, // 多行
            fit: true,
            columns: [[
                {field: 'chk', checkbox: true, width: 50},
                {field: 'gradeName', title: '年级名称', align:'center',width: 100},
                {field: 'teamName', title: '班级', align:'center',width: 120},
                {field: 'semesterName', title: '学期',align:'center', width: 100},
                {field: 'examName', title: '考试名称', align:'center',width: 200},
                {field: 'categoryName', title: '分类',align:'center', width: 100},
                {field: 'studentIdCard', title: '学生身份证号', align:'center', width: 200},
                {field: 'studentName', title: '学生姓名', align:'center',width: 100},
                {field: 'subject', title: '任教学科', align:'center',width: 100}
            ]]
        });
        let queryMyTeachScorePage= $("#dg_queryMyTeachScore").datagrid("getPager");
        $(queryMyTeachScorePage).pagination(pageParam);
    });
    //查询当前教师成绩
    function doQueryMyTeachScore() {
        // 验证条件：
        let gradeDatatableName=$("#myTeachGradeDatatableName").val();
        let teamName=$("#myTeachTeamName").val();
        let semesterName= $("#myTeachSemesterName").val();
        let examName= $("#myTeachExamName").val();
        let courseEnName=$("#myTeachCourseName").val();
        if (gradeDatatableName.length<=0) {$.messager.alert("提示","必须“选择年级”","info")}
        else if (teamName.length<=0) {$.messager.alert("提示","必须“选择班级”","info")}
        else if (semesterName.length<=0) {$.messager.alert("提示","必须“选择学期”","info")}
        else if (examName.length<=0) {$.messager.alert("提示","必须“选择考试”","info")}
        else if (courseEnName.length<=0) {$.messager.alert("提示","必须“选择学科”","info")}
        else {
            // 动态设置dataGrid页面的学科 title
            let subjectOption = $('#dg_queryMyTeachScore').datagrid("getColumnOption", "subject");
            let t = $("#myTeachCourseName").val();
            switch(t) {
                case "maths":
                    subjectOption.title="数学";
                    break;
                case "chinese":
                    subjectOption.title="语文";
                    break;
                case "english":
                    subjectOption.title="英语";
                    break;
                case "physics":
                    subjectOption.title="物理";
                    break;
                case "history":
                    subjectOption.title="历史";
                    break;
                case "chemistry":
                    subjectOption.title="化学";
                    break;
                case "biology":
                    subjectOption.title="生物";
                    break;
                case "politics":
                    subjectOption.title="政治";
                    break;
                case "geography":
                    subjectOption.title="地理";
                    break;
                case "sports":
                    subjectOption.title="体育";
                    break;
            }
            $("#dg_queryMyTeachScore").datagrid(); // 重置title后，分页也被重置了。
            //分页参数重新加载
            let pageParam = {
                pageSize: 10,							//每页显示的记录条数，默认为10
                pageList: [10, 100, 300, 500, 1000],	//可以设置每页记录条数的列表
                beforePageText: '第',        			//页数文本框前显示的汉字
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            }
            let queryMyTeachScorePage= $("#dg_queryMyTeachScore").datagrid("getPager");
            $(queryMyTeachScorePage).pagination(pageParam);

            $("#dg_queryMyTeachScore").datagrid("reload", {
            "gradeName": $("#myTeachGradeDatatableName").find("option:selected").text(),
            "gradeDatatableName": $("#myTeachGradeDatatableName").val(),
            "teamName": $("#myTeachTeamName").val(),
            "semesterName": $("#myTeachSemesterName").val(),
            "examName": $("#myTeachExamName").val(),
            "courseEnName":$("#myTeachCourseName").val()
            });
        }
    }
    //导出查询到的成绩doExportTeachScore
    function doExportTeachScore(){
        // 验证条件：
        let gradeDatatableName=$("#myTeachGradeDatatableName").val();
        let teamName=$("#myTeachTeamName").val();
        let semesterName= $("#myTeachSemesterName").val();
        let examName= $("#myTeachExamName").val();
        let courseEnName=$("#myTeachCourseName").val();
        if (gradeDatatableName.length<=0) {$.messager.alert("提示","必须“选择年级”","info")}
        else if (teamName.length<=0) {$.messager.alert("提示","必须“选择班级”","info")}
        else if (semesterName.length<=0) {$.messager.alert("提示","必须“选择学期”","info")}
        else if (examName.length<=0) {$.messager.alert("提示","必须“选择考试”","info")}
        else if (courseEnName.length<=0) {$.messager.alert("提示","必须“选择学科”","info")}
        else{
            let gradeName=$("#myTeachGradeDatatableName").find("option:selected").text();
            $("#teachGradeNameId").val(gradeName);
            $("#exportMyTeachScoreId").submit();
        }
    }
</script>
</body>
</html>